/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-05-28     vandoul       the first version
 */
#ifndef APPLICATIONS_SRV_PARAM_H_
#define APPLICATIONS_SRV_PARAM_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <cJSON.h>

#define SRV_PARAM_SERVICE_TYPE_NULL             0
#define SRV_PARAM_SERVICE_TYPE_MB_RTU           1
#define SRV_PARAM_SERVICE_TYPE_MB_TCP           2
#define SRV_PARAM_SERVICE_TYPE_TCP              3
#define SRV_PARAM_SERVICE_TYPE_MQTT             4

struct srv_param_app {
    char name[32];
    char from[32];
    char to[32];
    int from_type;
    int to_type;
    int addr;
    int base_reg;
    int reg_num;
    int function;
};
struct srv_param_rtu {
    char path[32];
    int baud;
    int data_bits;
    char parity;
    int stop_bits;
    int rts_pin;
};
struct srv_param_tcp {
    char addr[16];
    int port;
};
struct srv_param_mqtt {
    char url[64];
    char prefix[64];
};
struct srv_param_service {
    char name[32];
    int type;
    union {
        struct srv_param_rtu rtu;
        struct srv_param_tcp tcp;
        struct srv_param_mqtt mqtt;
    };
};
struct srv_param {
    char name[32];
    int app_num;
    struct srv_param_app *app_list;
    int srv_num;
    struct srv_param_service *srv_list;
};

struct srv_param *srv_param_config_load(const char *path);
cJSON *srv_param_to_cjson(struct srv_param *param);

#ifdef __cplusplus
}
#endif

#endif /* APPLICATIONS_SRV_PARAM_H_ */
